class DashboardController{
    constructor($interval,$timeout,$state,$rootScope,$scope,$cookies,UserService,AccountService){
        Object.assign(this,{$interval,$timeout,$state,$rootScope,$scope,$cookies,UserService,AccountService});
        this.$rootScope.isAtLotteryPage = false;
        //console.log(" $state.includes('*.lottery'): "+  $state.includes('*.lottery'));
        this.init();
        this.intervalObj=null;
        this.awardTipList= [];
    }
    init (){
        let self = this;
        self.AccountService.getAccountInfo({ignoreLoadingBar:true}).then(accountinfo_success).catch(accountinfo_error);
        function accountinfo_success(data) {
            self.$rootScope.lotteryAccountInfo =data;
        };
        function accountinfo_error(reason) {
            console.log(`AccountService.getAccountInfo:${JSON.stringify(reason)}`);
        };
        self.userData =  self.UserService.getUser();
        self.accessToken =self.$cookies.get("sessionId") || self.$cookies.get('token')|| sessionStorage.getItem('sessionId');
        self.accessToken = encodeURI(self.accessToken);
        self.up = encodeURI(URL_PREFIX);
        //中奖提示面板
        this.AccountService.getAwardTip({ignoreLoadingBar: true}).then(awardtip_success).catch(awardtip_error);
        self.intervalObj = self.$interval(() => {
            this.AccountService.getAwardTip({ignoreLoadingBar: true}).then(awardtip_success).catch(awardtip_error);
        }, 10000);
        function awardtip_success(data) {
            self.awardTipList = data.data.data_list;
            if(!self.$rootScope.awardtipMarquee){
                self.$timeout(function () {
                    self.marquee();
                },1000);
                self.$rootScope.awardtipMarquee  = true;
            }
        };
        function awardtip_error(reason) {
            console.log("getAwardTip(): "+JSON.stringify(reason));
        };
    }

    marquee(){
        let self = this;
        let extraPx = 20;
        let marqueeHeight = $('#lotteryAwardTip').height();
        let ulEle= $('#lotteryAwardTip ul');
        let ulHeight = ulEle.height()+extraPx;
        ulEle.animate({'top': '-'+(ulHeight)+'px'},15000);
        self.interval =  self.$interval(function(){
            ulEle.animate({'top': (marqueeHeight+extraPx) +'px'},10);
            self.$timeout(function(){
                ulEle.animate({'top': '-'+(ulHeight)+'px'},15000);
            },10);
        },15010);
    }

    logout(){
        //将this 赋值给self，在子函数中使用this，是引用子函数的this对象。
        let self = this;
        this.UserService.logout();
    }


}
DashboardController.$inject = ["$interval","$timeout","$state","$rootScope","$scope","$cookies","UserService","AccountService"];

export default DashboardController;